package com.yc.tomcat.impl;


import com.yc.tomcat.Cookie;
import com.yc.tomcat.HttpServletRequest;
import com.yc.tomcat.HttpServletResponse;
import com.yc.tomcat.ServletException;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("cookie.s")
public class CookieServlet  extends  HttpServletImpl{
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        Cookie[] cookies=request.getCookies();
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out= response.getWriter();
        if(cookies!=null){
            out.println("<ul>");
            for (Cookie cookie : cookies) {
                out.println("<li>");
                out.println(cookie.getName()+":"+cookie.getValue());
                out.println("</li>");
            }
            out.println("</ul>");
        }else {
            out.println("<h1>没有Cookie数据</h1>");
        }
    }
}
